﻿'---------------------------------------------------------------------
'THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
'KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
'IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
'PARTICULAR PURPOSE.
'---------------------------------------------------------------------
Imports System

Namespace Microsoft.Samples.Alert
    
    ''' <summary>
    ''' Event arguments used when an Alert option has been chosen.
    ''' </summary>
    Public Class AlertChoiceEventArgs
        Inherits EventArgs
        
        Private _result As AlertResult = AlertResult.None
        
        ''' <summary>
        ''' Builds an AlertChoiceEventArgs object.
        ''' </summary>
        ''' <param name="buttons">The types of buttons</param>
        ''' <param name="argument">The string argument the client returned</param>
        Public Sub New(ByVal buttons As AlertButtons, ByVal argument As String)
            MyBase.New()
            Select Case buttons
                Case AlertButtons.AbortRetryIgnore
                    Select Case argument
                        Case "true"
                            Result = AlertResult.Abort
                        Case "false"
                            Result = AlertResult.Retry
                        Case Else
                            Result = AlertResult.Ignore
                    End Select
                Case AlertButtons.OK
                    If (argument = "true") Then
                        Result = AlertResult.OK
                    Else
                        Result = AlertResult.None
                    End If
                Case AlertButtons.OKCancel
                    Select Case argument
                        Case "true"
                            Result = AlertResult.OK
                        Case "false"
                            Result = AlertResult.Cancel
                        Case Else
                            Result = AlertResult.None
                    End Select
                Case AlertButtons.RetryCancel
                    Select Case argument
                        Case "true"
                            Result = AlertResult.Retry
                        Case "false"
                            Result = AlertResult.Cancel
                        Case Else
                            Result = AlertResult.None
                    End Select
                Case AlertButtons.YesNo
                    Select Case argument
                        Case "true"
                            Result = AlertResult.Yes
                        Case "false"
                            Result = AlertResult.No
                        Case Else
                            Result = AlertResult.None
                    End Select
                Case AlertButtons.YesNoCancel
                    Select Case argument
                        Case "true"
                            Result = AlertResult.Yes
                        Case "false"
                            Result = AlertResult.No
                        Case Else
                            Result = AlertResult.Cancel
                    End Select
            End Select
        End Sub
        
        ''' <summary>
        ''' The chosen option in the Alert
        ''' </summary>
        Public Property Result As AlertResult
            Get
                Return _result
            End Get
            Set
                _result = value
            End Set
        End Property
    End Class
End Namespace
